<template>
  <div class="">
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
        <el-form-item label="卡查询：" prop="query">
          <el-input v-model="queryParams.query" placeholder="请输入卡名称" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="卡功能：" prop="type">
          <el-select v-model="queryParams.type" placeholder="请选择" clearable style="width: 240px">
            <el-option v-for="dict in typeList" :key="dict.id" :label="dict.value" :value="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="上链时间：" prop="">
          <el-date-picker v-model="date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <el-table v-loading="loading" :data="cardList" stripe border>
        <el-table-column label="序号" align="center" type="index" width="64px" />
        <el-table-column label="卡名称" align="center" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="卡功能" align="center" prop="type" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="typeList" :value="scope.row.type" />
          </template>
        </el-table-column>
        <el-table-column label="发行方" align="center" prop="issuerName" width="200" :show-overflow-tooltip="true" />
        <el-table-column label="发行店铺" align="center" prop="shopName" :show-overflow-tooltip="true">
        </el-table-column>
        <!-- <el-table-column label="状态" align="center" prop="sellStatusStr" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column label="上链时间" align="center" prop="issueTime" :show-overflow-tooltip="true" />
        <el-table-column label="持卡/总量" align="center" prop="holdCard" :show-overflow-tooltip="true" />
        <el-table-column label="售价" align="center" prop="price" :show-overflow-tooltip="true" />
        <el-table-column label="DDCid" align="center" prop="ddc" :show-overflow-tooltip="true" />
        <el-table-column label="交易哈希" align="center" prop="voucher" :show-overflow-tooltip="true" />
        <el-table-column label="销售状态" align="center"  :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            <dict-tag :options="salesStatusList" :value="scope.row.sellStatus" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="240" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleView(scope.row)">查看</el-button>
            <el-button size="mini" type="text" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="mini" type="text" v-if="scope.row.sellStatus==1" @click="updateCardList(scope.row,2)">上架</el-button>
            <el-button size="mini" type="text" v-if="scope.row.sellStatus==2" @click="updateCardList(scope.row,1)">下架</el-button>
            <el-button size="mini" type="text" @click="jumpCardmember(scope.row)">持卡会员</el-button>
            <el-button size="mini" type="text" @click="jumpCardDetail(scope.row)">持卡明细</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <DetailDialog v-if="detailDialog" :id="id" :visible.sync="detailDialog" :pathType="pathType" @success="_handleSuccess"></DetailDialog>
  </div>
</template>

<script>
  import {
    listEquityCardIssue,
    updateIssueStatus,
    exportEquityCardIssue,
    soldOut,
    equityCardIssueSort,
    sendShenyeAccount,
    virtualSubscribe,
    updateBatchSellStatus
  } from "@/api/equityManager/equityCardIssue";
  import {
    getList,
  } from "@/api/merchantsNFR/nfrIssue";
  import DetailDialog from "@/views/merchantsNFR/nfrIssue/issueComponents/DetailDialog";
  export default {
    // dicts: ['equity_card_issue_type', 'equity_card_sell_status'],
    name: "",
    components: {
      DetailDialog,
    },
    data() {
      return {
        //日期
        date: [],
        // 遮罩层
        loading: false,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 发行管理表格数据
        cardList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          query: '', //权益卡名称
          startTime: '', //可售开始时间
          endTime: '', //可售结束时间
          type: '', //卡功能
        },
        typeList: [], //卡功能
        salesStatusList: [], //销售状态
        detailDialog: false,
        id: '',
        pathType: '',
      };
    },
    created() {
      this.getDictIssueType();
      this.getList();
      console.log(this.dict)
    },
    methods: {
      //获取卡功能字典
      getDictIssueType() {
        var dictType = "merchant_equity_card_type,merchant_equity_card_sell_status";
        this.$getSelectList(dictType)
          .then((res) => {
            this.typeList = res.result[0].dictList;
            this.salesStatusList = res.result[1].dictList;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      /** 查询发行管理列表 */
      getList() {
        this.loading = true;
        getList(this.queryParams).then(response => {
          this.cardList = response.result.records;
          this.total = response.result.total;
          this.loading = false;
        });
      },
      /** 上下架按钮操作 */
      updateCardList(row,status) {
        let title = '上架'
        if (status == 2) { //上架
          title = '上架'
        } else {
          title = '下架'
        }
        var merchantEquityIdList = []
        merchantEquityIdList.push(row.id)
          let data = {
            merchantEquityIdList:merchantEquityIdList,
            sellStatus:status
          }
          updateBatchSellStatus(data).then(response => {
            this.$message({
              type: 'success',
              message: title + '成功!'
            });
            // this.resetQuery()
            this.getList();
          });
      },
      // 表单重置
      reset() {
        this.date = []
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          query: '', //权益卡名称
          startTime: '', //可售开始时间
          endTime: '', //可售结束时间
          type: '', //发行方式
        }
        // this.resetForm("form");
        this.handleQuery()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.startTime = this.date[0];
        this.queryParams.endTime = this.date[1];
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        // this.resetForm("queryForm");
        this.reset();
      },
      /** 修改按钮操作 */
      handleEdit(row) {
        this.id = row.id
        this.detailDialog = true
        this.pathType = 'edit'
      },
      /** 详情按钮操作 */
      handleView(row) {
        this.id = row.id
        this.detailDialog = true
        this.pathType = 'detail'
      },
      /** 当前售罄按钮操作 */
      sellOut(row) {
        this.$confirm('是否执行此操作', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let data = {
            id: row.id,
          }
          soldOut(data).then(response => {
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            // this.resetQuery()
            this.getList();
          });

        }).catch(() => {});
      },
      /** 持卡会员 */
      jumpCardmember(row) {
        this.$router.push({
          path: "/merchantsNFR/nfrIssue/cardmember",
          query: {
            id: row.id,
          },
        });
      },
      /** 持卡明细 */
      jumpCardDetail(row) {
        this.$router.push({
          path: "/merchantsNFR/nfrIssue/cardDetails",
          query: {
            id: row.id,
            equityIssueId: row.equityIssueId,
            type: 'nfrIssue'
          },
        })
      },
      /** 打入神椰账号按钮操作 */
      drivingSY(row) {
        this.$confirm('是否打入神椰账号', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          sendShenyeAccount(row.id).then(response => {
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            this.getList();
          });
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$modal.confirm('是否确认导出所有发行管理数据项？').then(() => {
          this.exportLoading = true;
          return exportEquityCardIssue(queryParams);
        }).then(response => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      },
      _handleSuccess() {
        this.getList();
        // this.getNum();
        this.detailDialog = false;
      },
    }
  };

</script>
<style scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 20px;
  }

</style>
